{% extends 'base.html' %}
{% block title %}用户注册{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card shadow-sm mt-5">
                <div class="card-body">
                    <h2 class="text-center my-4">用户注册</h2>
                    <form class="form-control" method="post" action="{{ url_for('user.register') }}">
                        <input type="hidden" id="csrf_token" name="csrf_token" value="{{ csrf_token }}">
                        
                        <div class="mb-3">
                            <label for="loginname" class="form-label">用户名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="loginname" name="loginname" 
                                   placeholder="请输入2-20个字符(中英文、数字、下划线)" required 
                                   pattern="^[\u4e00-\u9fa5a-zA-Z0-9_]{2,20}$" maxlength="20">
                            <div class="form-text">用户名将用于登录，请使用中文、英文、数字或下划线</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="nickname" class="form-label">昵称 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="nickname" name="nickname" 
                                   placeholder="请输入您的昵称" required maxlength="30">
                            <div class="form-text">昵称最多30个字符</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="email" class="form-label">邮箱 <span class="text-danger">*</span></label>
                            <input type="email" class="form-control" id="email" name="email" 
                                   placeholder="请输入有效的邮箱地址" required>
                            <div class="form-text">用于接收系统通知和密码找回</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="phone" class="form-label">手机号</label>
                            <input type="text" class="form-control" id="phone" name="phone" 
                                   placeholder="请输入手机号(必填)" required pattern="^(\+)?[0-9]{10,15}$">
                            <div class="form-text">可选字段，格式如: +8613800138000 或 13800138000</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="password" class="form-label">密码 <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" id="password" name="password" value="123456" 
                                   placeholder="请输入密码" required minlength="6">
                            <div class="form-text">密码长度至少6个字符</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="confirm_password" class="form-label">确认密码 <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" id="confirm_password" name="confirm_password" value="123456" 
                                   placeholder="请再次输入密码" required minlength="6">
                            <div class="form-text">请再次输入相同的密码</div>
                        </div>
                        
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">注册</button>
                        </div>
                        
                        <div class="mt-3 text-center">
                            <p>已有账号？<a href="{{ url_for('user.login') }}" class="text-decoration-none">立即登录</a></p>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const form = document.querySelector('form');
        const password = document.getElementById('password');
        const confirmPassword = document.getElementById('confirm_password');
        
        // 表单提交前验证
        form.addEventListener('submit', function(event) {
            // 验证密码匹配
            if (password.value !== confirmPassword.value) {
                event.preventDefault();
                alert('两次输入的密码不一致');
                confirmPassword.focus();
            }
            
            // 其他验证已通过HTML5表单验证属性实现
        });
    });
</script>
{% endblock %}